<?php

namespace App\Jobs;

use App\Models\Posts\WxPost;
use App\Models\Circle\WxCircle;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class UpdateCircleInfoJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $circle_id = 0;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($circle_id)
    {
        //
        $this->circle_id = $circle_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        if(_empty_($this->circle_id)){
            return;
        }
        $circle = WxCircle::find($this->circle_id);
        if(_empty_($circle)){
            _logger_(__file__,__line__, '查找用户失败' . $this->circle_id);
            return;
        }
        $circle_name = $circle->circle_name;
        $head_portrait = $circle->head_portrait;

        WxPost::withoutSyncingToSearch(function () use (&$circle_name){
            WxPost::where('circle_id',$this->circle_id)->update([
                'circle_name' => $circle_name,
            ]);
        });
    }
}
